package pers.fulsun.es.test._03_doc;

import java.io.IOException;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import pers.fulsun.es.test._01_ESClient;

public class _02_ESTest_Doc_Update {
  private static RestHighLevelClient client = _01_ESClient.getClient();

  public static void main(String[] args) throws IOException {
    // 修改文档 - 请求对象
    UpdateRequest request = new UpdateRequest();
    // 配置修改参数
    request.index("user").id("1008");
    // 设置请求体，对数据进行修改
    request.doc(XContentType.JSON, "sex", "女");
    // 添加文档数据，数据格式为 JSON 格式
    UpdateResponse response = client.update(request, RequestOptions.DEFAULT);
    // 客户端发送请求，获取响应对象
    //// 3.打印结果信息
    System.out.println("_index:" + response.getIndex());
    System.out.println("_id:" + response.getId());
    System.out.println("_result:" + response.getResult());
    // 关闭客户端连接
    client.close();
  }
}
